package com.tbfs.common;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;



public abstract class AbsBaseDaoImpl extends SqlMapClientDaoSupport implements IBaseDao{
	
	
	/**
	 * 返回插入语句
	 */
	protected abstract String getInsertSql();
	
	/**
	 * 返回更新语句,更新对象的每一个值。
	 */
	protected abstract String getUpdateByPrimaryKeySql();
	
	/**
	 * 返回更新语句,只更新对象中不为空的值。
	 */
	protected abstract String getUpdateByPrimaryKeySelectiveSql();
	
	/**
	 * 返回删除语句。 
	 */
	protected abstract String getDeleteByPrimaryKeySql();
	
	
	/**
	 * 返回根据条件查询结果集的语句
	 * @return
	 */
	protected abstract String getQueryBySelectiveSql();
	
	/**
	 * 返回根据条件查询总数量的语句
	 * @return
	 */
	protected abstract String getQueryBySelectiveCountSql();
	
	/**
	 * 返回根据ID查询的语句。 
	 */
	protected abstract String getSelectByEntityIdSql();


	public void insert(Object param) {
		getSqlMapClientTemplate().insert(getInsertSql(), param);
	}

	public int updateByPrimaryKey(Object param) {
		int row = getSqlMapClientTemplate().update(getUpdateByPrimaryKeySql(), param);
		return row;
	}

	public int updateByPrimaryKeySelective(Object record) {
		int row = getSqlMapClientTemplate().update(getUpdateByPrimaryKeySelectiveSql(), record);
		return row;
	}

	public int deleteByPrimaryKey(Object record) {
		int row = getSqlMapClientTemplate().delete(getDeleteByPrimaryKeySql(), record);
		return row;
	}

	public List queryBySelective(Object param) {
		return getSqlMapClientTemplate().queryForList(getQueryBySelectiveSql(), param);
	}
	

	public Integer queryCountBySelective(Object param) {
		// TODO Auto-generated method stub
		return (Integer)getSqlMapClientTemplate().queryForObject(getQueryBySelectiveCountSql(), param);
	}

	public BaseEntity selectByEntityId(Object srcRecord) {
		// TODO Auto-generated method stub
		return (BaseEntity)getSqlMapClientTemplate().queryForObject(getQueryBySelectiveSql(), srcRecord);
	}



}
